package com.wy17113.controller.utils;

import java.security.MessageDigest;

public class EncoderByMd5 {
	private static String byteArrayToHexString(byte[] bts) {
		StringBuffer des = new StringBuffer();
		String tmp = null;

		for (int i = 0; i < bts.length; i++) {
			tmp = Integer.toHexString(bts[i] & 0xFF);
			if (tmp.length() == 1) {
				des.append("0");
			}
			des.append(tmp);
		}
		return des.toString();
	}

	public static String getEncoderByMd5(String originString) {
		if (originString != null) {
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");

				byte[] results = md.digest(originString.getBytes());

				String resultString = byteArrayToHexString(results);
				return resultString.toUpperCase();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		return originString;
	}

	public static void main(String[] args) {
		System.out.println("MD5:" + getEncoderByMd5("123456"));
	}
}